﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;

public class winOrLose : MonoBehaviour
{
    public GameObject obj;
    public Text scoreT;
    public Text LifeT;
    private int score = 0;
    private int life = 3;

    public AudioClip hurt;

    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        scoreT.text = "Score:" + score.ToString();
        LifeT.text = "Life:" + life.ToString();
        score++;

        if(this.transform.position.y < -0.5){
            AudioSource.PlayClipAtPoint(hurt,gameObject.transform.position);
            life--;
            LifeT.text = "Life:" + life.ToString();
            if(life <= 0){
                PlayerPrefs.SetString("score", score.ToString());
                SceneManager.LoadScene("GameOver");
            }
            this.transform.position = new Vector3(0.4f, 1.5f, -1.23f);
            this.transform.forward = obj.transform.position - this.transform.position;
        }
    }
}
